﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GameLib.Serialization;
using GameLib.Gameplay;
using System.IO;
using GameLib.WorldMap;

namespace Sandbox.Serialization.Serializers
{
	public class PlaySerializer : Serializer<Play>
	{
		public override DataType DataType
		{
			get { return GameDataTypes.Play; }
		}

		public override bool Deserialize(Play obj, string dataPath)
		{
			var play = obj;

			// get the folder out of the full path
			string dirName = Path.GetDirectoryName(dataPath);

			// load global info
			DataHandler.Read(play.World.Terrains, Path.Combine(dirName, "World/TerrainDefines.xml"));

			// load maps
			string[] mapNames = Directory.GetFiles(Path.Combine(dirName, "Maps"));

			foreach (string mapName in mapNames)
			{
				Map map = new Map();
				DataHandler.Read(map, mapName);
				play.World.Maps.Add(map);
			}

			return true;
		}

		public override bool Serialize(Play obj, string dataPath)
		{
			throw new NotImplementedException();
		}
	}
}
